<template>
<h1>菜单组件</h1>
  <el-menu @select="handleSelect" active-text-color="yellow" mode="horizontal" background-color="lightblue" text-color="red">
    <el-menu-item index="1">首页</el-menu-item>
    <el-menu-item index="2">免费课</el-menu-item>
    <el-menu-item index="3">直播课</el-menu-item>
    <el-menu-item index="4">线上课</el-menu-item>
    <el-menu-item index="5">脱产课</el-menu-item>
    <el-sub-menu index="6">
      <template #title>关于我们</template>
      <el-menu-item index="6-1">联系我们</el-menu-item>
      <el-menu-item index="6-2">公司地址</el-menu-item>
      <el-menu-item index="6-3">求职招聘</el-menu-item>
    </el-sub-menu>
  </el-menu>
</template>

<script setup>
import { ElMessage } from 'element-plus'
//index指的是当前选中的是哪个菜单项,比如选中"线上课",index的值为4
//indexPath指的是如何到达当前选中的这个菜单项,比如6,6-3即可找到"求职招聘"
const handleSelect = (key, keyPath) => {
  console.log(key, keyPath)
  if(key==3){
    ElMessage.success('您选择了直播课!');
  }
}
</script>


<style scoped>

</style>